package com.steak.concurrent.CompletableFuture.api.supply;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/2713:28
 */
public class supplyAsyncUseExecutors {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService threadPool = Executors.newCachedThreadPool();
        CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("开始执行有返回值的异步任务");
            return "我是小四哥";
        }, threadPool);
        System.out.println(future.get());
        threadPool.shutdown();
    }
}
